//----------------------------------Include-------------------------------------
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "mcu.h"
#include "board.h"
#include "glbvar.h"
//------------------------------------------------------------------------------
//global var defined in this file
#define  SC7A20_GLOBALS
#include "sc7a20.h"
//------------------------------------------------------------------------------

//----------------------------------Globals-------------------------------------
t_acc                   gt_acc;
//------------------------------------------------------------------------------

//-----------------------------------Macro--------------------------------------
#define RUN_IDLE        0
#define RUN_TRIG        1
//------------------------------------------------------------------------------

//---------------------------------Static Var-----------------------------------
static uint32_t    nu32_rs = RUN_IDLE;
static uint64_t    nu64_time_tick = 0;
//------------------------------------------------------------------------------
static uint8_t     nu8_reg[8];
//------------------------------------------------------------------------------

//--------------------------------Static Func-----------------------------------
//------------------------------------------------------------------------------

//--------------------------------Public Func-----------------------------------
void sc7a20_cyc(void)
{
  switch(nu32_rs){
  case RUN_IDLE:
    if(igu64_tick_10ms > nu64_time_tick + 100){
      nu64_time_tick = igu64_tick_10ms;
      gt_acc.who = brd_sc7a20_rd_one_byte(RADDR_WHO_AM_I);
      brd_sc7a20_rd_n_byte(RADDR_OUT_X_L, nu8_reg, 6);
      gt_acc.x = (int16_t)((nu8_reg[1]<<8) + nu8_reg[0]);  gt_acc.x = gt_acc.x*ACC_RANGE/32768;
      gt_acc.y = (int16_t)((nu8_reg[3]<<8) + nu8_reg[2]);  gt_acc.y = gt_acc.y*ACC_RANGE/32768;
      gt_acc.z = (int16_t)((nu8_reg[5]<<8) + nu8_reg[4]);  gt_acc.z = gt_acc.z*ACC_RANGE/32768;
    }
    break;
  default: break;
  }
}
//------------------------------------EOF---------------------------------------


